package jianzhiOfferII;


//剑指 Offer II 008. 和大于等于 target 的最短子数组
public class Num008_minSubArrayLen {
    public int minSubArrayLen(int target, int[] nums) {
        int start = 0;
        int sum = 0;
        int res = 0;
        for (int j = 0; j < nums.length; j++) {
            sum += nums[j];
            while (sum - nums[start] >= target){
                sum -= nums[start];
                start++;
            }
            if (sum >= target){
                if (res == 0 || res > j - start + 1){
                    res = j - start + 1;
                }
            }


        }
        return res;

    }
}
